package com.letoy.edu.service.Impl;

import com.letoy.edu.dao.ScheduleMapper;
import com.letoy.edu.entity.CourseSchedule;
import com.letoy.edu.service.ScheduleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;

@Service
public class ScheduleServiceImpl implements ScheduleService {

    @Autowired
    ScheduleMapper scheduleMapper;

    @Override
    public HashMap<String, Object> findAllSchedule() {

        HashMap<String, Object> hashMap = new HashMap<>();

        List<CourseSchedule> scheduleList = scheduleMapper.findAllSchedule();

        if (scheduleList.isEmpty()) {
            hashMap.put("status", "1");
            hashMap.put("msg", "查询失败");
            return hashMap;
        }
        hashMap.put("status", "0");
        hashMap.put("msg", "查询成功");
        hashMap.put("data", scheduleList);
        return hashMap;
    }

    @Override
    public HashMap<String, Object> updateScheduleByClassNumber(CourseSchedule courseSchedule) {

        HashMap<String, Object> hashMap = new HashMap<>();
        int result = scheduleMapper.updateScheduleByClassNumber(courseSchedule);

        if (result == 0) {
            hashMap.put("status", "1");
            hashMap.put("msg", "更新失败");
            return hashMap;
        }
        hashMap.put("status", "0");
        hashMap.put("msg", "更新成功");
        return hashMap;
    }
}
